package com.example.demo.controller;

import cn.hutool.core.bean.BeanUtil;
import com.example.demo.entity.DTO.WorkersDTO;
import com.example.demo.entity.VO.WorkersVO;
import com.example.demo.entity.Workers;
import com.example.demo.result.Result;
import com.example.demo.service.IWorkersService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;

/**
 * <p>
 * 员工表 前端控制器
 * </p>
 *
 * @author Mr.wyy
 * @since 2024-05-30
 */
@Api(tags = "员工接口")
@RestController
@RequestMapping("/workers")
public class WorkersController {

    @Resource
    private IWorkersService workersService;

    /**
     * 查询所有接口
     * @return
     */
    @ApiOperationSupport(author = "Mr.wyy")
    @ApiOperation(value = "根据内容查询所有信息接口")
    @PostMapping("/findAllByCriteria")
    public Result<List<WorkersDTO>> findAll(@RequestBody WorkersVO workersVO) {
        Workers workers = new Workers();
        BeanUtil.copyProperties(workersVO,workers);
        return Result.success().msg("查询成功").data(workersService.selectByCriteria(workers));
    }

    /**
     * 根据内容查找所有接口
     * @return
     */
    @ApiOperationSupport(author = "Mr.sdy")
    @ApiOperation(value = "随机推送护理人员接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "num",value = "返回随机数",required = true)
    })
    @PostMapping("/randomGoods")
    public Result<List<WorkersDTO>> randomGoods(@RequestParam Integer num) {
        // 查询所有商品信息
        List<WorkersDTO> allByCriteria = workersService.selectByCriteria(null);

        // 打乱列表中的元素顺序，以确保后续选取的元素是随机的。
        Collections.shuffle(allByCriteria);

        // 截取列表的前num个元素
        allByCriteria = allByCriteria.subList(0, num);


        return Result.success().msg("查询成功").data(allByCriteria);
    }

    /**
     * 根据id查询数据接口
     * @param id
     * @return
     *//*
    @ApiOperationSupport(author = "Mr.wyy")
    @ApiOperation(value = "根据id查询数据接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "组件id",required = true)
    })
    @GetMapping("/{id}")
    public Result<Workers> findOne(@PathVariable Integer id) {
        return Result.success(workersService.getById(id)).msg("查询成功");
    }*/



   /* *//**
    * 新增
    * @param
    * @return
    *//*
    @ApiOperationSupport(author = "Mr.wyy")
    @ApiOperation(value = "新增")
    @PostMapping("/add")
    //TODO 记得来创建这个VO
    public Result<String> add() {
        //TODO VO转Entity
        //workersService.saveOrUpdate(workers);
        return Result.success().msg("添加成功");
    }*/

    /**
     * 删除接口
     * @param id
     * @return
     */
/*
    @ApiOperationSupport(author = "Mr.wyy")
    @ApiOperation(value = "删除接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "组件id",required = true)
    })
    @DeleteMapping("/{id}")
    public Result<String> delete(@PathVariable Integer id) {
        workersService.removeById(id);
        return Result.success().msg("删除成功");
    }
*/

    /**
     * 批量删除接口
     * @param ids
     * @return
     *//*
    @ApiOperationSupport(author = "Mr.wyy")
    @ApiOperation(value = "批量删除接口")
    @PostMapping("/del/batch")
    public Result<String> deleteBatch(@RequestBody List<Integer> ids) {
        workersService.removeByIds(ids);
        return Result.success().msg("批量删除成功");
    }*/
}